package com.dmy.chat.server.netty.command.factory;

import com.dmy.chat.server.netty.UserChannelBind;
import com.dmy.chat.server.netty.command.EventType;
import com.dmy.chat.server.netty.command.UserChatCommand;
import com.dmy.chat.server.netty.command.UserEventCommand;
import com.dmy.chat.server.netty.command.UserLoginCommand;
import com.dmy.chat.server.netty.message.Messages;
import io.netty.channel.Channel;

/**
 * create by YCQ for 2020/1/15 12:56
 */
public class UserEventCommandFactory {

    public UserEventCommand getCommand(UserChannelBind userChannelBind, Channel channel, Messages messages) {
        int cmd = messages.getCmd();
        EventType eventType = EventType.valueOf(cmd);

        UserEventCommand result = null;
        switch (eventType){
            case CHAT_SEND:
                result = new UserChatCommand(userChannelBind,channel,messages);
                break;
            case LOGIN:
                result = new UserLoginCommand(userChannelBind,channel,messages);
                break;
            default:
                throw new RuntimeException("未识别的命令类型");
        }


        return result;
    }
}
